package com.homegoods.login.ui;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.homegoods.login.R;
import com.homegoods.login.databinding.LoginUserAgreementActivityBindingImpl;
import com.homegoods.aroutercomment.ARouterPath;
import com.kedll.library.KBaseActivity;


/**
 * @author QiQi
 * 用户协议
 */
@Route(path = ARouterPath.PATH_USER_AGREEMENT)
public class UserAgreementActivity extends KBaseActivity<LoginUserAgreementActivityBindingImpl> {


    private WebView webView;

    @Override
    protected int getLayout() {
        return R.layout.login_user_agreement_activity;
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        webView = mBinding.serviceAgreement;
    }

    @Override
    protected void initEvent() {
        getData();
    }

    private void getData() {
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);
                return true;
            }
        });

        WebSettings webSettings = webView.getSettings();
        webSettings.setUseWideViewPort(true);//设置此属性，可任意比例缩放
        webSettings.setLoadWithOverviewMode(true);// 缩放至屏幕的大小
        //便页面支持缩放：
        webSettings.setBuiltInZoomControls(true);
        webSettings.setSupportZoom(false);
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);  //关闭webview中缓存
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); //支持内容重新布局
        webView.loadUrl("http://116.62.124.85:8080/xddFront/systemFullText.do?id=5");
    }

    public void onClick(View view) {
        close(RESULT_OK);
    }

    private void close(int resultCole) {
        setResult(resultCole);
        finish();
        overridePendingTransition(R.anim.hold, R.anim.top_out_600);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            close(RESULT_CANCELED);
        }
        return super.onKeyDown(keyCode, event);
    }
}
